package com.wang.controller;

import com.wang.param.PostCollectionQueryParam;
import com.wang.param.PostQueryParam;
import com.wang.param.PostReviewParam;
import com.wang.param.PostSubmitParam;
import com.wang.reponse.PostVo;
import com.wang.result.BaseResponse;
import com.wang.result.ResultUtils;
import com.wang.user.service.PostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/post")
@Api(tags = "帖子管理")
public class PostController {
    @Resource
    private PostService postService;

    @PostMapping("/submit")
    @ApiOperation(value = "发布帖子")
    public BaseResponse<Boolean> submit(@RequestBody PostSubmitParam submitParam) {
        return ResultUtils.success(postService.submit(submitParam));
    }

    @GetMapping("/detail/{id}")
    @ApiOperation(value = "查看帖子详情")
    public BaseResponse<PostVo> detail(@PathVariable("id") Integer id) {
        return ResultUtils.success(postService.detailById(id));
    }

    @PostMapping("/review")
    @ApiOperation(value = "审核帖子")
    public BaseResponse<Boolean> review(@RequestBody PostReviewParam reviewParam) {
        return ResultUtils.success(postService.review(reviewParam));
    }

    @GetMapping("/listByShopId")
    @ApiOperation(value = "查看指定商铺下的帖子")
    public BaseResponse<List<PostVo>> listByShopId(PostCollectionQueryParam queryParam) {
        return ResultUtils.success(postService.listByShopId(queryParam));
    }

    @GetMapping("/review/list")
    @ApiOperation(value = "查看所有待审核的帖子列表")
    public BaseResponse<List<PostVo>> reviewList( PostCollectionQueryParam queryParam) {
        return ResultUtils.success(postService.reviewList(queryParam));
    }

    @GetMapping("/list")
    @ApiOperation(value = "查看所有的帖子")
    public BaseResponse<List<PostVo>> list(PostCollectionQueryParam queryParam) {
        return ResultUtils.success(postService.list(queryParam));
    }

    @GetMapping("/myList")
    @ApiOperation(value = "用户查看自己发布的所有帖子")
    public BaseResponse<List<PostVo>> myList(PostCollectionQueryParam queryParam) {
        return ResultUtils.success(postService.myList(queryParam));
    }

    @GetMapping("/admin/list")
    @ApiOperation(value = "管理员查看所有的帖子")
    public BaseResponse<List<PostVo>> adminList(PostCollectionQueryParam queryParam) {
        return ResultUtils.success(postService.adminList(queryParam));
    }
}
